import { useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import Creator from "../store/actions";
// 引入api
import CommsApi from "../api/comms";

export const useAllComms = () => {
    // 获取全部父类型数据
    const allComms = useSelector(state => {
        return state.allComms
    })
    const dispatch = useDispatch();
    // 操作状态的行为
    // 获取所有父类型
    const getAllComms = useCallback(async () => {
        const data = await CommsApi.getAllComms()
        dispatch(Creator.getAllComms({data}));
    }, [dispatch]);

    return [allComms, { getAllComms}]

}